//
//  HRSignViewModel.m
//  Hear
//
//  Created by mac on 2018/3/7.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "HRSignViewModel.h"

@implementation HRSignViewModel
-(void)getDailyMission:(NSDictionary *)requstDict isSeccess:(void(^)(HRSignInModel *signInModel))isSeccess{
    YTKApi *api = [YTKApi apiGetWithUrl:@"UserInfo/Get_GetDailyMission" para:requstDict];
    api.cacheTime = 1;
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            NSDictionary *dict = request.responseJSONObject;
            
            if ([dict[@"CodeStatus"] intValue] == 20000){
                HRSignInModel *signInModel = [HRSignInModel modelWithJSON:dict[@"BodyContent"]];
                signInModel.signInfoModel = [HRSignInModel modelWithJSON:signInModel.signInfo];
                signInModel.taskInfoModelArr = [NSArray modelArrayWithClass:[HRSignInModel class] json:signInModel.taskInfo];
                isSeccess(signInModel);
            }else{
                isSeccess(nil);
            }
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            isSeccess(nil);
        }];
    }];
}
-(void)saveUserSignIn:(NSDictionary *)requstDict isSeccess:(void(^)(BOOL isSeccess))isSeccess{
    YTKApi *api = [YTKApi apiPostWithUrl:@"UserInfo/Post_SaveUserSignIn" para:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            NSDictionary *dict = request.responseJSONObject;
            if ([dict[@"CodeStatus"] intValue] == 20000){
                
                isSeccess(YES);
            }else{
                isSeccess(NO);
            }
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            isSeccess(NO);
        }];
    }];
}

-(void)saveUserShareRecord:(NSDictionary *)requstDict isSeccess:(void(^)(BOOL isSeccess))isSeccess{
    YTKApi *api = [YTKApi apiPostWithUrl:@"UserInfo/Post_SaveUserShareRecord" para:requstDict];
    [api getSuccessToken:^() {
        api.foceNoTocken = NO;
        [api setRequestSerializerType:YTKRequestSerializerTypeJSON];
        [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
            NSDictionary *dict = request.responseJSONObject;
            if ([dict[@"CodeStatus"] intValue] == 20000){
                
                isSeccess(YES);
            }else{
                isSeccess(NO);
            }
        } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
            isSeccess(NO);
        }];
    }];
}


@end
